<?php

namespace MoChat\ClientNew\Action;

use Carbon\Carbon;
use Hyperf\DbConnection\Db;
use MoChat\ClientNew\Model\ClientFollowRecord;
use MoChat\ClientNew\Model\ClientNew;
use MoChat\Framework\Action\AbstractAction;
use MoChat\Framework\Constants\ErrorCode;
use MoChat\Framework\Exception\CommonException;
use MoChat\Framework\Request\ValidateSceneTrait;
use MoChat\App\Common\Middleware\DashboardAuthMiddleware;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\Middlewares;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Qbhy\HyperfAuth\AuthManager;

/**
 * @Controller
 */
class DetailLicence extends AbstractAction
{
    use ValidateSceneTrait;


    protected $auth;

    /**
     * @Middlewares({
     *     @Middleware(DashboardAuthMiddleware::class)
     * })
     * @RequestMapping(path="/client-new/detailLicence", methods="get")
     */
    public function handle(): array
    {
        $params = $this->request->all();
        $user =user();
        if (empty($user)) {
            throw new CommonException(ErrorCode::AUTH_UNAUTHORIZED, '登入异常请重新登入');
        }

        $Client=ClientNew::query()->where('id',$params['clientId'])->first()->toArray();
        $res=Db::connection('b2b')->table('user')->where('unique_id',$Client['uniqueId'])
            ->leftJoin('licence as l','l.id','=','user.id')->select('user.id','l.*')->first();

        $data=[];
        if ($res){
            $data=[
                ['name'=>'营业执照','licence_time'=>$res->BUSINESS_LICENCE],
                ['name'=>'组织机构代码证','licence_time'=>$res->BUSINESS_LICENCE],
                ['name'=>'生产(经营)许可证','licence_time'=>$res->BUSINESS_LICENCE],
                ['name'=>'GMP(GSP)证书','licence_time'=>$res->BUSINESS_LICENCE],
                ['name'=>'医疗机构执业许可证','licence_time'=>$res->BUSINESS_LICENCE],
                ['name'=>'采购委托书','licence_time'=>$res->BUSINESS_LICENCE],
            ];
        }


        return $data;
    }
}
